package cn.lvji.springboot.learn5.vo;

import java.io.Serializable;

/**
 * 响应对象
 *
 * @author verne
 */
public class Response<T> implements Serializable {
    /**
     * 
     */
    private static final long serialVersionUID = 7475351490371277894L;
    protected int code = 200;
    protected String msg = "success";
    protected T data;
    public final static int SUCCESS_CODE = 200;
    
    public static final Response<Void> RPC_BILLING_ERROR = new Response<Void>(10, "远程调用计费微服务出错！");
    public static final Response<Void> RPC_USER_ERROR = new Response<Void>(11, "远程调用用户微服务出错！");
    public static final Response<Void> DATA_FORMAT_ERROR = new Response<Void>(12, "数据格式错误！");
    public static final Response<Void> JSON_DATA_FORMAT_ERROR = new Response<Void>(13, "JSON格式化错误！");
    
    public static final Response<Void> SUCCESS = new Response<Void>(200, "success!");
    
    public static final Response<Void> CREATED = new Response<Void>(201, "created!");
    public static final Response<Void> ACCEPTED  = new Response<Void>(202, "accepted!");
    public static final Response<Void> NON_AUTHORITATIVE_INFORMATION  = new Response<Void>(203, "non-authoritative information!");
    public static final Response<Void> NO_CONTENT  = new Response<Void>(204, "no content!");
    
    
    public static final Response<Void> INVALID_REQUEST  = new Response<Void>(400, "invalid request!");
    public static final Response<Void> UNAUTHORIZED  = new Response<Void>(401, "unauthorized!");
    public static final Response<Void> FORBIDDEN  = new Response<Void>(403, "forbidden!");
    public static final Response<Void> NOT_FOUND = new Response<Void>(404, "not found！");
    public static final Response<Void> CONFLICT = new Response<Void>(404, "conflict！");
    public static final Response<Void> NOT_ACCEPTABLE = new Response<Void>(406, "not acceptable！");
    public static final Response<Void> REQUEST_TIMEOUT = new Response<Void>(406, "request timeout！");
    public static final Response<Void> GONE = new Response<Void>(410, "gone！");
    public static final Response<Void> UNPROCESABLE_ENTITY = new Response<Void>(422, "unprocesable entity！");

    public static final Response<Void> SERVER_ERROR = new Response<Void>(500, "internal server error！");
    public static final Response<Void> BAD_GATEWAY  = new Response<Void>(502, "bad gateway！");
    public static final Response<Void> SERVICE_UNAVAILABLE = new Response<Void>(503, "service unavailable！");
    public static final Response<Void> GATEWAY_TIMEOUT = new Response<Void>(504, "gateway timeout！");
    public static final Response<Void> VERSION_NOT_SUPPORTED = new Response<Void>(505, "version not supported！");
    
    public Response(int code, String msg) {
        this.code = code;
        this.msg = msg;
    }

    public Response(T data) {
        this.data = data;
    }

    public Response(int code, String msg, T data) {
        this.code = code;
        this.msg = msg;
        this.data = data;
    }

    public Response() {
        super();
    }

    public int getCode() {
        return code;
    }

    public String getMsg() {
        return msg;
    }


    public T getData() {
        return data;
    }

    @Override
    public int hashCode() {
        final int prime = 31;
        int result = 1;
        result = prime * result + code;
        result = prime * result + ((data == null) ? 0 : data.hashCode());
        result = prime * result + ((msg == null) ? 0 : msg.hashCode());
        return result;
    }

    @Override
    public boolean equals(Object obj) {
        if (this == obj) {
            return true;
        }
        if (obj == null) {
            return false;
        }
        if (getClass() != obj.getClass()) {
            return false;
        }
        @SuppressWarnings("rawtypes")
        Response other = (Response) obj;
        if (code != other.code) {
            return false;
        }
        if (data == null) {
            if (other.data != null) {
                return false;
            }
        } else if (!data.equals(other.data)) {
            return false;
        }
        if (msg == null) {
            if (other.msg != null) {
                return false;
            }
        } else if (!msg.equals(other.msg)) {
            return false;
        }
        return true;
    }

    public void setCode(int code) {
        this.code = code;
    }

    public void setMsg(String msg) {
        this.msg = msg;
    }

    public void setData(T data) {
        this.data = data;
    }

    @Override
    public String toString() {
        return "Response [code=" + code + ", msg=" + msg + ", data=" + data + "]";
    }

}
